package com.fs.global.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import static java.util.Collections.singletonList;

@EnableOpenApi   // 开启Swagger自定义接口文档
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build()
                .globalRequestParameters(
                singletonList(new springfox.documentation.builders.RequestParameterBuilder()
                        .name("Authentication")
                        .description("请求令牌")
                        .in(ParameterType.HEADER)
                        .required(false)
                        .build()));
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("共享茶室API文档")
                .description("文档描述：更多问题，请联系开发者")
                .contact(new Contact("", "", ""))
                .version("1.0")
                .build();
    }

}
